home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / Clueless.swf / scripts / Forms / ProfileCreatePopupForm.as < prev    next >
Encoding:
Text File  |  2011-10-17  |  2.8 KB  |  94 lines

  1. package Forms
  2. {
  3.    import flash.display.*;
  4.    import flash.events.*;
  5.    import flash.geom.*;
  6.    import flash.system.*;
  7.    import flash.text.*;
  8.    
  9.    [Embed(source="/_assets/assets.swf", symbol="Forms.ProfileCreatePopupForm")]
  10.    public class ProfileCreatePopupForm extends CluelessBaseForm
  11.    {
  12.        
  13.       
  14.       private var tmpText:String;
  15.       
  16.       public var _tfTextName:TextField;
  17.       
  18.       public var _ErrorMessage_mc:MovieClip;
  19.       
  20.       public var _bBack:SimpleButton;
  21.       
  22.       public var _bCreate:SimpleButton;
  23.       
  24.       public function ProfileCreatePopupForm()
  25.       {
  26.          super();
  27.          setBackButton(_bBack);
  28.          installMouseOverSound(_bBack);
  29.          _tfTextName.alwaysShowSelection = true;
  30.          tmpText = "";
  31.          _tfTextName.text = "";
  32.          _tfTextName.addEventListener(TextEvent.TEXT_INPUT,textInputCapture);
  33.          _ErrorMessage_mc.visible = false;
  34.          _bCreate.addEventListener(MouseEvent.CLICK,onCreateClicked,false,0,true);
  35.          _ErrorMessage_mc.addEventListener(MouseEvent.CLICK,onErrorClicked,false,0,true);
  36.       }
  37.       
  38.       protected function onCreateClicked(param1:MouseEvent) : void
  39.       {
  40.          if(_tfTextName.text.length > 0)
  41.          {
  42.             if(_tfTextName.text.charCodeAt(0) == 32)
  43.             {
  44.                _ErrorMessage_mc._txtError.text = "Please start with Alphanumeric characters";
  45.                _ErrorMessage_mc.visible = true;
  46.             }
  47.             else if(Profile.getProfile(_tfTextName.text) == null)
  48.             {
  49.                if(Profile.ProfileList.length == 0)
  50.                {
  51.                   Storage.getInstance().newProfile(_tfTextName.text);
  52.                   Profile.CurrentProfile = Profile.getProfile(_tfTextName.text);
  53.                   Storage.getInstance().saveProfiles();
  54.                }
  55.                else
  56.                {
  57.                   Storage.getInstance().newProfile(_tfTextName.text);
  58.                }
  59.                onBack(new MouseEvent(""));
  60.             }
  61.             else
  62.             {
  63.                _ErrorMessage_mc._txtError.text = "Name already exists.  Please use another name";
  64.                _ErrorMessage_mc.visible = true;
  65.             }
  66.          }
  67.       }
  68.       
  69.       protected function onErrorClicked(param1:MouseEvent) : void
  70.       {
  71.          _ErrorMessage_mc.visible = false;
  72.       }
  73.       
  74.       override public function onFocus() : void
  75.       {
  76.          super.onFocus();
  77.          _stageCurrent.focus = _tfTextName;
  78.       }
  79.       
  80.       public function textInputCapture(param1:TextEvent) : void
  81.       {
  82.          trace(_tfTextName.textWidth);
  83.          if(_tfTextName.textWidth > 330)
  84.          {
  85.             _tfTextName.maxChars = _tfTextName.length;
  86.          }
  87.          else
  88.          {
  89.             _tfTextName.maxChars = 25;
  90.          }
  91.       }
  92.    }
  93. }
  94.